﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Ninject;
using MVCCornucopia.Models;
using MVCCornucopia.Controllers;

namespace MVCCornucopia.Common
{
    public class DependencyInjectionController : DefaultControllerFactory
    {
        private IKernel kernel;

        public DependencyInjectionController()
        {
            kernel = new StandardKernel();
            AddBindings();
        }

        protected override IController GetControllerInstance(System.Web.Routing.RequestContext requestContext, Type controllerType)
        {

            return (controllerType == null) ? null : (IController)kernel.Get(controllerType);
        }

        private void AddBindings()
        {
            kernel.Bind<IRepository>().To<EmployeeRepository>().WhenInjectedInto<EmployeeController>();

        }
    }

}